[BugFix] Fix json_set crash and json_delete no-op with $.key paths (#5167)#5339
Conversation
…pensearch-project#5167) convertToJsonPath() unconditionally prepends "$." to input paths. When users pass standard JSONPath syntax like "$.name", the path becomes "$.$.name" (double-prefixed), causing json_set to crash with HTTP 500 and json_delete to silently return unchanged JSON. Strip any existing "$." or "$" prefix before processing to prevent double-prefixing while preserving the curly-brace-to-bracket conversion. Signed-off-by: Heng Qian <qianheng@amazon.com>
Decision LogRoot Cause: Approach: Strip any existing Alternatives Rejected:
Pitfalls: None encountered — the fix is localized to one utility method. All existing tests (unit + integration + YAML) continue to pass. Things to Watch: The |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
Nit: Add two more regression test cases for |
| if (input.startsWith("$.")) { | ||
| input = input.substring(2); | ||
| } else if (input.startsWith("$")) { | ||
| input = input.substring(1); | ||
| } |
There was a problem hiding this comment.
Could the input start with other invalid char? for example $$.name, etc.
There was a problem hiding this comment.
This is the minimal change that handles all prefix variants (\$, \$., or none)
No, $$. is not standard JSONPath.
Description
json_setcrashes (HTTP 500) andjson_deletesilently returns unchanged JSON when using standard JSONPath$.keysyntax. The root cause isconvertToJsonPath()inJsonUtils.java, which unconditionally prepends$.to the input — turning$.nameinto$.$.name(double-prefixed).The fix strips any existing
$.or$prefix from the input before processing, preventing double-prefixing while preserving the existing curly-brace-to-bracket conversion logic.Related Issues
Resolves #5167, #5170
Check List
-s)spotlessCheckpassed